'''
data.txt中保存有n个单词，每个单词一行。
请编写一个程序从文件中将单词读出，找到最长的单词，
然后将其保存到result.txt中。程序须保存test.py中

输出格式：

用以下格式输出最长的字符串到**result.txt**中:
The longest word is: zhang
如果有多个单词，则每个单词用**英文逗号**间隔(结尾无**逗号**)：
The longest words are: zhang,xiang
'''
x1 = []
x2 = []
with open('data.txt','r') as f:
    fi = f.readlines()
    for i in range(len(fi)):
        fi[i] = fi[i].strip()
        x1.append(len(fi[i]))
    m = max(x1)
    for i in range(len(fi)):
        if len(fi[i]) == m:
            if fi[i] not in x2:
                x2.append(fi[i])
        
with open('result.txt','w') as g:
    if len(x2) == 1:
        g.write('The longest word is: {0}'.format(x2[0]))
    else :
        a = ','.join(x2)
        g.write('The longest words are: {0}'.format(a))
g.close()
        
        
        
